package com.cby.library.common.network

import com.cby.library.common.network.converter.StringConverterFactory
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @description: RetrofitManager
 *
 * @author ChenBaoyang
 * @date 2021/10/20 17:11
 */
object RetrofitManager {

    /**
     * 创建retrofit
     * @param baseUrl
     * @return
     */
    fun createRetrofit(baseUrl: String): Retrofit {
        return createRetrofit(baseUrl, HttpClientProvider.defaultHttpClient)
    }

    /**
     * 创建retrofit
     * @param baseUrl
     * @param okHttpClient
     * @return
     */
    fun createRetrofit(baseUrl: String, okHttpClient: OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(StringConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync())
            .client(okHttpClient)
            .build()
    }
}